#@layout()
<script>
    $("#fairadvertisement-edit").validate({
        rules:{
                "fairAdvertisement.picture":{
                    required:true
                },
                "fairAdvertisement.url":{
                    required:true
                },
                "fairAdvertisement.deletetag":{
                    required:true
                },
                "fairAdvertisement.create_time":{
                    required:true
                },
                "fairAdvertisement.sort":{
                    required:true
                },
                "fairAdvertisement.name":{
                    required:true
                }
        },
        messages:{

                "fairAdvertisement.picture":{
                required:"请输入广告图片..."
                },
                "fairAdvertisement.url":{
                required:"请输入点击url..."
                },
                "fairAdvertisement.deletetag":{
                required:"请输入..."
                },
                "fairAdvertisement.create_time":{
                required:"请输入添加时间..."
                },
                "fairAdvertisement.sort":{
                required:"请输入..."
                },
                "fairAdvertisement.name":{
                required:"请输入广告图片名称..."
                }
        },
        onkeyup:false,
        focusCleanup:true,
        success:"valid",
        submitHandler:function(form){
        var config = {
        "url":"/admin/fairadvertisement/updateById",
        data:$("#fairadvertisement-edit").serialize(),
        "method":"POST"
        };
        var backendTool = new BackendTool(config);
        backendTool.ajaxRequest();
        }
    });
    
    function initUploader(id,width,height){
    	var srcStr;
        var uploader = WebUploader.create({
            auto: true,
            duplicate:true,
            swf:  '#(contextPath)/assets/front/web/script/upload/Uploader.swf',
            server: '#(contextPath)/admin/upload?category=app-',
            pick: {
                id:id
            },
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
            }
        });
        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var up=$(id+"_prew");
            // 创建缩略图
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                up.html('文件正在上传中，请稍候')
            }, width, height);
        });
        //文件上传成功处理
        uploader.on( 'uploadSuccess', function( file,resp ) {
        	var up=$(id+"_prew");
        	
        	if(id=="#fileClick"){
        		var s='<img src="'+resp._raw+'" style="border-radius:50%;" width="55px;">';
        	}else{
        		var s='<img src="'+resp._raw+'"  width="200px;">';
        	}
        	
        	up.html(s);
        	$(id+"_hidden").val(resp._raw);
        });
        //文件上传失败处理
        uploader.on( 'uploadError', function( file ) {
        	layer.alert(file.name+"上传失败！！")
        });
        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
        });
    }  
    
    $(document).ready(function(){
    	initUploader('#advertiseImg',"100","100");
    });
</script>
#define main()
    <form class="form form-horizontal" id="fairadvertisement-edit">
    #include("fairadvertisement-form.html")
    </form>
#end